﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading.Tasks;
using HighDivePrinter.View;
using HighDivePrinter.Properties;
using HighDivePrinter.Presenter;
using HighDivePrinter.Model;



namespace HighDivePrinter
{
    public partial class FormContest : Form, IFormContest
    {
        private int _row = -1;
        public FormContest()
        {
            InitializeComponent();
        }

        private void _buttonNewContest_Click(object sender, EventArgs e)
        {
            if (this.EventAddContest != null)
                this.EventAddContest();
        }

        private void _buttonSaveContest_Click(object sender, EventArgs e)
        {
            if (this.EventSaveContest != null)
                this.EventSaveContest();
        }

        private void _buttonReadContest_Click(object sender, EventArgs e)
        {
            if (this.EventReadContest != null)
                this.EventReadContest();
        }

        private void _buttonDeleteContest_Click(object sender, EventArgs e)
        {
            //this._row = this._dataGridView.Rows.
            if (this._row != -1)
                if (this.EventRemoveContest != null)
                    this.EventRemoveContest(this._row);
            this._row = 1;

        }

        #region IFormContest Members

        //Diver Class members
        void IFormContest.SetContestList(BindingList<Contest> contests)
        {
            this._dataGridView.DataSource = contests;
        }

        public event DelegateAddContest EventAddContest = null;
        public event DelegateRemoveContest EventRemoveContest = null;
        public event DelegateSaveContest EventSaveContest = null;
        public event DelegateReadContest EventReadContest = null;

        #endregion

        private void _dataGridView_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            //contest
            this._row = e.RowIndex;
        }

        #region Printing

        /// <summary>
        /// Händelsemetod för att hantera EVENT ButtonClick
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void _buttonPrint_Click(object sender, EventArgs e)
        {
           PrintDocumentContest cl = new PrintDocumentContest((BindingList<Contest>)this._dataGridView.DataSource);
           cl.MyPrint();
        }

        #endregion

        private void FormContest_Load(object sender, EventArgs e)
        {

        }
        

    
      
    }
}
